package testcase.command;

import java.io.ByteArrayInputStream;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.NoSuchElementException;

import org.junit.Test;

import satir.card.Choice;
import satir.card.Question;
import satir.command.AskQuestionCmd;
import satir.framework.test.PrivateAccessor;
import satir.player.Player;
import junit.framework.TestCase;


public class In_AskQuestionCmd_2 extends TestCase{
	/*
	 * Test Case: 1
	 * Objective: Test Integration of AskQuestionCmd, Player, Question and Choice, to award correct Self-Esteem value for Q1 C1 to player
	 */
	@Test
	public void testQuestion1C1AwardSEValue(){	
		ArrayList<Choice> choices;
		choices = new ArrayList<Choice>();
		choices.add(new Choice("Blame him/her and prohibit use the phone more than 5 mins.", 1, new Hashtable<String, Integer>()));
		choices.add(new Choice("Talk with son/daughter and find the reason.", 1, new Hashtable<String, Integer>()));
		choices.add(new Choice("Threaten son/daughter. If the situation still not change, you will modify the amount of pocket money.", -1, new Hashtable<String, Integer>()));
		choices.add(new Choice("Ignore him/her.", -1, new Hashtable<String, Integer>()));
		
		String question1 = "Mother notices her children talk with classmate at night about 30 mins or more. As Father, what is your decision?";
		Player player = new Player();
		Question question = new Question(question1, choices);
		AskQuestionCmd askQuestionCmd = new AskQuestionCmd(question, player);

		String input = "1";
		System.setIn(new ByteArrayInputStream(input.getBytes()));
		try {
			askQuestionCmd.execute();
		} catch (NoSuchElementException e) {
		}
		int actualResult = ((Integer) PrivateAccessor.getPrivateField(
				player, "selfEsteem")).intValue();
		assertEquals(6,actualResult);
	}
	
	/*
	 * Test Case: 2
	 * Objective: Test Integration of AskQuestionCmd, Player, Question and Choice, to award correct Self-Esteem value for Q1 C2 to player
	 */
	@Test 
	public void testQuestion1C2AwardSEValue(){
		
		ArrayList<Choice> choices;
		choices = new ArrayList<Choice>();
		choices.add(new Choice("Blame him/her and prohibit use the phone more than 5 mins.", 1, new Hashtable<String, Integer>()));
		choices.add(new Choice("Talk with son/daughter and find the reason.", 1, new Hashtable<String, Integer>()));
		choices.add(new Choice("Threaten son/daughter. If the situation still not change, you will modify the amount of pocket money.", -1, new Hashtable<String, Integer>()));
		choices.add(new Choice("Ignore him/her.", -1, new Hashtable<String, Integer>()));
		
		String question1 = "Mother notices her children talk with classmate at night about 30 mins or more. As Father, what is your decision?";
		Player player = new Player();
		Question question = new Question(question1, choices);
		AskQuestionCmd askQuestionCmd = new AskQuestionCmd(question, player);

		String input = "2";
		System.setIn(new ByteArrayInputStream(input.getBytes()));
		try {
			askQuestionCmd.execute();
		} catch (NoSuchElementException e) {
		}
		int actualResult = ((Integer) PrivateAccessor.getPrivateField(
				player, "selfEsteem")).intValue();
		assertEquals(6,actualResult);
	}
	
	/*
	 * Test Case: 3
	 * 	 * Objective: Test Integration of AskQuestionCmd, Player, Question and Choice, to award correct Self-Esteem value for Q1 C3 to player
	 */
	@Test 
	public void testQuestion1C3AwardSEValue(){
		
		ArrayList<Choice> choices;
		choices = new ArrayList<Choice>();
		choices.add(new Choice("Blame him/her and prohibit use the phone more than 5 mins.", 1, new Hashtable<String, Integer>()));
		choices.add(new Choice("Talk with son/daughter and find the reason.", 1, new Hashtable<String, Integer>()));
		choices.add(new Choice("Threaten son/daughter. If the situation still not change, you will modify the amount of pocket money.", -1, new Hashtable<String, Integer>()));
		choices.add(new Choice("Ignore him/her.", -1, new Hashtable<String, Integer>()));
		
		String question1 = "Mother notices her children talk with classmate at night about 30 mins or more. As Father, what is your decision?";
		Player player = new Player();
		Question question = new Question(question1, choices);
		AskQuestionCmd askQuestionCmd = new AskQuestionCmd(question, player);

		String input = "3";
		System.setIn(new ByteArrayInputStream(input.getBytes()));
		try {
			askQuestionCmd.execute();
		} catch (NoSuchElementException e) {
		}
		int actualResult = ((Integer) PrivateAccessor.getPrivateField(
				player, "selfEsteem")).intValue();
		assertEquals(4,actualResult);
	}
	
	/*
	 * Test Case: 4
	 * 	 * Objective: Test Integration of AskQuestionCmd, Player, Question and Choice, to award correct Self-Esteem value for Q1 C4 to player
	 */
	@Test 
	public void testQuestion1C4AwardSEValue(){
		
		ArrayList<Choice> choices;
		choices = new ArrayList<Choice>();
		choices.add(new Choice("Blame him/her and prohibit use the phone more than 5 mins.", 1, new Hashtable<String, Integer>()));
		choices.add(new Choice("Talk with son/daughter and find the reason.", 1, new Hashtable<String, Integer>()));
		choices.add(new Choice("Threaten son/daughter. If the situation still not change, you will modify the amount of pocket money.", -1, new Hashtable<String, Integer>()));
		choices.add(new Choice("Ignore him/her.", -1, new Hashtable<String, Integer>()));
		
		String question1 = "Mother notices her children talk with classmate at night about 30 mins or more. As Father, what is your decision?";
		Player player = new Player();
		Question question = new Question(question1, choices);
		AskQuestionCmd askQuestionCmd = new AskQuestionCmd(question, player);

		String input = "4";
		System.setIn(new ByteArrayInputStream(input.getBytes()));
		try {
			askQuestionCmd.execute();
		} catch (NoSuchElementException e) {
		}
		int actualResult = ((Integer) PrivateAccessor.getPrivateField(
				player, "selfEsteem")).intValue();
		assertEquals(4,actualResult);
	}
	
	/*
	 * Test Case: 5
	 * 	 * Objective: Test Integration of AskQuestionCmd, Player, Question and Choice, to award correct Self-Esteem value for Q2 C1 to player
	 */
	@Test 
	public void testQuestion2C1AwardSEValue(){
		
		ArrayList<Choice> choices;
		choices = new ArrayList<Choice>();
		choices.add(new Choice("You decide to go and lie to parent.", -2, new Hashtable<String, Integer>()));
		choices.add(new Choice("Talk with son/daughter and find the reason.", 1, new Hashtable<String, Integer>()));
		choices.add(new Choice("You will discuss with parent about the revision time.", 5, new Hashtable<String, Integer>()));
		choices.add(new Choice("Ask bother or sister to give advice.", 1, new Hashtable<String, Integer>()));
		
		String question2 = "Your children is facing the examination, Father prohibits his/her go outside since his/her Chinese subject result is only got 60 marks\nBut he/she is invited to attend the brithday party on this Saturday. As childern, What is your decision?";
		Player player = new Player();
		Question question = new Question(question2, choices);
		AskQuestionCmd askQuestionCmd = new AskQuestionCmd(question, player);

		String input = "1";
		System.setIn(new ByteArrayInputStream(input.getBytes()));
		try {
			askQuestionCmd.execute();
		} catch (NoSuchElementException e) {
		}
		int actualResult = ((Integer) PrivateAccessor.getPrivateField(
				player, "selfEsteem")).intValue();
		assertEquals(3,actualResult);
	}
	
	/*
	 * Test Case: 6
	 * 	 * Objective: Test Integration of AskQuestionCmd, Player, Question and Choice, to award correct Self-Esteem value for Q2 C2 to player
	 */
	@Test 
	public void testQuestion2C2AwardSEValue(){
		
		ArrayList<Choice> choices;
		choices = new ArrayList<Choice>();
		choices.add(new Choice("You decide to go and lie to parent.", -2, new Hashtable<String, Integer>()));
		choices.add(new Choice("Talk with son/daughter and find the reason.", 1, new Hashtable<String, Integer>()));
		choices.add(new Choice("You will discuss with parent about the revision time.", 5, new Hashtable<String, Integer>()));
		choices.add(new Choice("Ask bother or sister to give advice.", 1, new Hashtable<String, Integer>()));
		
		String question2 = "Your children is facing the examination, Father prohibits his/her go outside since his/her Chinese subject result is only got 60 marks\nBut he/she is invited to attend the brithday party on this Saturday. As childern, What is your decision?";
		Player player = new Player();
		Question question = new Question(question2, choices);
		AskQuestionCmd askQuestionCmd = new AskQuestionCmd(question, player);
		String input = "2";
		System.setIn(new ByteArrayInputStream(input.getBytes()));
		try {
			askQuestionCmd.execute();
		} catch (NoSuchElementException e) {
		}
		int actualResult = ((Integer) PrivateAccessor.getPrivateField(
				player, "selfEsteem")).intValue();
		assertEquals(6,actualResult);
	}
	
	/*
	 * Test Case: 7
	 * 	 * Objective: Test Integration of AskQuestionCmd, Player, Question and Choice, to award correct Self-Esteem value for Q2 C3 to player 
	 */
	@Test 
	public void testQuestion2C3AwardSEValue(){
		ArrayList<Choice> choices;
		choices = new ArrayList<Choice>();
		choices.add(new Choice("You decide to go and lie to parent.", -2, new Hashtable<String, Integer>()));
		choices.add(new Choice("Talk with son/daughter and find the reason.", 1, new Hashtable<String, Integer>()));
		choices.add(new Choice("You will discuss with parent about the revision time.", 5, new Hashtable<String, Integer>()));
		choices.add(new Choice("Ask bother or sister to give advice.", 1, new Hashtable<String, Integer>()));
		
		String question2 = "Your children is facing the examination, Father prohibits his/her go outside since his/her Chinese subject result is only got 60 marks\nBut he/she is invited to attend the brithday party on this Saturday. As childern, What is your decision?";
		Player player = new Player();
		Question question = new Question(question2, choices);
		AskQuestionCmd askQuestionCmd = new AskQuestionCmd(question, player);
		String input = "3";
		System.setIn(new ByteArrayInputStream(input.getBytes()));
		try {
			askQuestionCmd.execute();
		} catch (NoSuchElementException e) {
		}
		int actualResult = ((Integer) PrivateAccessor.getPrivateField(
				player, "selfEsteem")).intValue();
		assertEquals(10,actualResult);
	}
	
	/*
	 * Test Case: 8
	 * 	 * Objective: Test Integration of AskQuestionCmd, Player, Question and Choice, to award correct Self-Esteem value for Q2 C4 to player
	 */
	@Test 
	public void testQuestion2C4AwardSEValue(){
		
		ArrayList<Choice> choices;
		choices = new ArrayList<Choice>();
		choices.add(new Choice("You decide to go and lie to parent.", -2, new Hashtable<String, Integer>()));
		choices.add(new Choice("Talk with son/daughter and find the reason.", 1, new Hashtable<String, Integer>()));
		choices.add(new Choice("You will discuss with parent about the revision time.", 5, new Hashtable<String, Integer>()));
		choices.add(new Choice("Ask bother or sister to give advice.", 1, new Hashtable<String, Integer>()));
		
		String question2 = "Your children is facing the examination, Father prohibits his/her go outside since his/her Chinese subject result is only got 60 marks\nBut he/she is invited to attend the brithday party on this Saturday. As childern, What is your decision?";
		Player player = new Player();
		Question question = new Question(question2, choices);
		AskQuestionCmd askQuestionCmd = new AskQuestionCmd(question, player);
		String input = "4";
		System.setIn(new ByteArrayInputStream(input.getBytes()));
		try {
			askQuestionCmd.execute();
		} catch (NoSuchElementException e) {
		}
		int actualResult = ((Integer) PrivateAccessor.getPrivateField(
				player, "selfEsteem")).intValue();
		assertEquals(6,actualResult);
	}
	
}
